//
//  CZQOderDetailVC.m
//  coachmanage
//
//  Created by 众拳科技 on 2018/3/21.
//  Copyright © 2018年 众拳科技. All rights reserved.
//

#import "CZQOderDetailVC.h"
#import "CZQOderDetailView.h"
#import "CZQOderDetalTCell.h"
@interface CZQOderDetailVC ()<UITableViewDelegate,UITableViewDataSource>
/**
 //数据源
 */
@property(nonatomic,strong)NSMutableArray *dataArr;


/**
 tableView
 */
@property(nonatomic,weak)UITableView *tableView;


/**
 table头
 */
@property(nonatomic,weak)CZQOderDetailView *headView;

@end

@implementation CZQOderDetailVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.title = @"订单详情";
    
    
    
    [self handleData];
    
}

-(void)handleData
{
    NSString *time = [NSString stringWithFormat:@"%@至%@",self.oder.BeginDateTime,self.oder.EndDateTime];
    
    NSArray *arr1 = @[@{@"项目名称":self.oder.Project},@{@"有效时间":time},@{@"服务地址":self.oder.Address},@{@"服务要求":self.oder.Memo}];
    
    [self.dataArr addObject:arr1];
    
    NSArray *arr2 = @[@{@"订单信息":self.oder.Title},@{@"意向金":self.oder.WannaFee},@{@"实付款":self.oder.FactFee},@{@"订单类型":self.oder.PayStatus},@{@"下单时间":self.oder.AddTime},@{@"订单号":self.oder.OrderNum}];
 
    [self.dataArr addObject:arr2];
    
    [self.tableView reloadData];

}

#pragma mark -- 懒加载

-(NSMutableArray *)dataArr
{
    if (!_dataArr) {
        
        _dataArr = [NSMutableArray array];
        
    }
    
    return _dataArr;
}

-(UITableView *)tableView
{
    if (!_tableView) {
        
        UITableView *tableView=[[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStyleGrouped];
        
        tableView.delegate=self;
        
        tableView.dataSource=self;
        
        tableView.backgroundColor = [UIColor whiteColor];
        
        tableView.estimatedRowHeight = 50;
        
        [self.view addSubview:tableView];
        
        [tableView mas_makeConstraints:^(MASConstraintMaker *make) {
            
            make.edges.mas_equalTo(self.view);
            
        }];
        
        CZQOderDetailView *head = [CZQOderDetailView new];
        
        NSString *status;
        
        if ([self.oder.Status integerValue] == 0) {
            status = @"已付款";
        }else if ([self.oder.Status integerValue] == 1)
        {
            status = @"已取消";
            
        }else
        {
            
            status = @"已结束";
        }
        head.oderProInputView.titleTF.text = status;
        [head.headImageView sd_setImageWithURL:[Helper imageUrlStringToChinese:self.oder.Pic imageType:nil] placeholderImage:PlaceHold];
        head.nickNameLabel.text = self.oder.Name;
        head.sexImage.image = [self.oder.Sex integerValue] == 0?[UIImage imageNamed:@"icon_male"]:[UIImage imageNamed:@"icon_female"];
        
        head.ageLabel.text = [NSString stringWithFormat:@"年龄：0岁"];
        
//        head.phoneLabel.text = self.oder.te
        
        self.headView = head;
        
        [self.view addSubview:head];
        
        [head mas_remakeConstraints:^(MASConstraintMaker *make) {
            
            make.top.mas_equalTo(tableView);
            
            make.left.width.mas_equalTo(self.view);
            
//            make.height.mas_offset(200);
        }];
        
        [head setNeedsLayout];
        [head layoutIfNeeded];
        
        tableView.tableHeaderView = head;
        
        //        tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        
        
        //注册
        //                [tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
        
        [tableView registerNib:[UINib nibWithNibName:@"CZQOderDetalTCell" bundle:nil]  forCellReuseIdentifier:@"cell"];
        
        //        [tableView registerNib:[UINib nibWithNibName:@"YDTrainingTableViewCell" bundle:nil]  forCellReuseIdentifier:@"cell"];
        
        _tableView = tableView;
    }
    return _tableView;
}

#pragma mark - UITableViewDataSource

//行数
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return self.dataArr.count;
}

//列数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    
    NSArray *arr = [self.dataArr objectAtIndex:section];
    
    return arr.count;
}

//cell内容
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    CZQOderDetalTCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    
    NSArray *arr = [self.dataArr objectAtIndex:indexPath.section];
    
    NSDictionary *dic = arr[indexPath.row];
    
    cell.nameLable.text = [[dic allKeys] lastObject];
    
    cell.titleLable.text = [dic objectForKey:cell.nameLable.text];
    
    if (indexPath.section == 1) {
        tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    }
    
    return cell  ;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    
    if (section == 0) {
        return 0.00001;
    }
    return 60;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0.00001;
}


-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    
    return [[UIView alloc]initWithFrame:CGRectZero];
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    
    if (section == 1) {
        
        UIView *bgView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, 60)];
        bgView.backgroundColor = BackGroundColor;
        
        NSArray *arr = @[@"联系用户",@"联系客服"];
        
        for (int i = 0; i < 2; i ++ ) {
            
            UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
            
            [btn setTitleEdgeInsets:UIEdgeInsetsMake(0, 10, 0, 0)];
            
            btn.backgroundColor = CSWhiteColor;
            
            btn.frame = CGRectMake(i *kScreenWidth/2, 0, kScreenWidth/2, 50);
            
            [btn setImage:arr[i]];
            
            [btn setTitle:arr[i]];
            
            btn.titleLabel.font = [UIFont systemFontOfSize:16];
            
            [btn setTitleColor:TextColor1];
            
            
            [bgView addSubview:btn];
            
        }
        
        return bgView;
        
    }
    return [[UIView alloc]initWithFrame:CGRectZero];
}



-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    //当离开某行时，让某行的选中状态消失
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
